package com.moonLight.weblog.admin.controller;

import com.moonLight.weblog.admin.service.AdminFileService;
import com.moonLight.weblog.common.aspect.ApiOperationLog;
import com.moonLight.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin")
@Api(tags = "Admin 文件模块")
public class AdminFileController {

    @Autowired
    private AdminFileService fileService;

    @PostMapping("/file/upload")
    @ApiOperation(value = "文件上传")
    @ApiOperationLog(description = "文件上传")
    public Response uploadFile(@RequestParam MultipartFile file) {
        //文件上传接口并非使用 JSON 格式进行提交，而是使用 Form 表达来提交的，所以入参的注解使用的 @RequestParam , 并使用了 MultipartFile 类接收上传的文件。
        return fileService.uploadFile(file);
    }

}
